<?php

Class ReportController extends Controller{
    
    public function actionIndex(){
        $model = new Questions();
        $questions = new CActiveDataProvider($model);
 
        $this->render("Report", array(
            "questions" => $questions
        ));
        
    }
    
    public function actionReportDetail($id = null){
        $model = new Answers();
        $criteria = new CDbCriteria();
        $criteria->compare("ques_id", $id);
        
        $ansReport = new CActiveDataProvider($model, array(
            "criteria" => $criteria
        ));
        
        $choice = Choice::model()->findByPk($id);
    //    $ansReport = new CActiveDataProvider($model);
        $aa=array();
      for($i=1;$i<=5;$i++){
      $cntCriteria = new CDbCriteria();
      $ch = "choice".$i;
     // echo "ch == $ch<br/>";
     $cntCriteria->condition = "ques_id = :ques_id";
     $cntCriteria->addCondition("ans_name = :ans_name");
     $cntCriteria->params[':ques_id'] = $id;
     $cntCriteria->params[':ans_name'] = $choice[$ch];
      $articleCount = Answers::model()->count($cntCriteria);
      $aa[] = $articleCount;
     // echo "articleCount == $articleCount<br/>";
      }
     // print_r($aa);
        $this->render("ReportDetail", array(
            "ansReport" => $ansReport,
            "choice" => $choice,
            "aa" => $aa
        ));
           
    }
}

?>